<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected function _initDb()
	{
		$config = new Zend_Config_Ini(APPLICATION_PATH.'/configs/application.ini',
			'develop'
		);
		$db = Zend_Db::factory($config->resources->db);
		$db->query('SET NAMES UTF8');
        Zend_Db_Table_Abstract::setDefaultAdapter($db);
        Zend_Registry::set('db' , $db);
	}
	
    protected function _initAutoload()
    {
        $autoloader = new Zend_Application_Module_Autoloader(
        array(
            'namespace' => '',
            'basePath'  => APPLICATION_PATH
        ));

        
        $autoloader->addResourceTypes(array(
	    'App' => array(
	        'path'      =>'/library/App/',
	        'namespace' => 'App_',
	    )));
        return $autoloader;
    }
   
    protected function _initView()
    {
    	$this->bootstrap('layout');
    	$layout = $this->getResource('layout');
    	$layout->setLayout('default');
    	$view = $layout->getView();
    	$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8');
    	$view->headTitle('Интернет магазин "Заморский сундочок"');
    	$view->headTitle()->setSeparator(' - ');
    }
    
    protected function _initPlugins()
    {
        $frontController = Zend_Controller_Front::getInstance();
        $frontController->registerPlugin(new App_Plugin_SetCookie());
    }
    
    protected function _initCache()
    {
            $frontendOptions = array(
               'lifetime' => 7200*720000, 
               'automatic_serialization' => true
            );
            
            $backendOptions = array(
                'cache_dir' => $_SERVER['DOCUMENT_ROOT'].'/data/cache/'
            );
            $cache = Zend_Cache::factory('Core',
                                         'File',
                                         $frontendOptions,
                                         $backendOptions);
            Zend_Registry::set('cache',$cache);
    }
} 